/* http_fetcher_internal.h - HTTP handling functions used internally

    HTTP Fetcher
    Copyright (C) 2001, 2003 Lyle Hanson (lhanson@users.sourceforge.net)

    This library is free software; you can redistribute it and/or
    modify it under the terms of the GNU Library General Public
    License as published by the Free Software Foundation; either
    version 2 of the License, or (at your option) any later version.

    This library is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    Library General Public License for more details.

    See LICENSE file for details
                                    
 */

#ifndef HTTP_FETCHER_INTERNAL_H
#define HTTP_FETCHER_INTERNAL_H

#ifdef WIN32
typedef unsigned short in_port_t;
#else
#include <netinet/in.h>
#endif

/*****************************************************************************/
/**** The following functions are used INTERNALLY by http-fetcher ************/
/*****************************************************************************/

    /*
     * Takes a url and (depending on proxy settings) sets the appropriate
     *  host variable and composes the appropriate HTTP request.  Note that
     *  the URL (and the host variable, when set) may have a portnumber on the
     *  end.
	 * Global pointer 'host' as well as the buffer pointed to by the return
	 *	value are allocated and must be freed by the caller.
     * Returns:
     *  a pointer to the allocated request buffer on success, or
     *  NULL on error
     */
static char *hfetcher__composeRequest(const char *url);

    /*
     * Reads the metadata of an HTTP response.
     * Returns:
     *  A pointer to the buffer containing HTTP metadata, or
     *  NULL on error
     */
static char *hfetcher__read_header(int sock);

    /*
     * Opens a TCP socket and returns the descriptor
     * Returns:
     *  socket descriptor, or
     *  -1 on error
     */
static int hfetcher__makeSocket(const char *host);

	/*
	 * Determines if the given NULL-terminated buffer is large enough to
	 *	concatenate the given number of characters.  If not, it attempts to
	 *	grow the buffer to fit.
	 * Returns:
	 * 	0 on success, or
	 * 	-1 on error (original buffer is unchanged).
	 */
static int hfetcher__checkBufSize(char **buf, int *bufsize, int more);

#endif
